/**
 * @Class User
 * @Description 该文件定义User 类 描述RBAC模型中的用户
 * @Author Administrator
 * @Date 2022-10-21  15:32
 * @version 1.0.0
 */
package com.bosssoft.hr.train.j2se.example.pojo;
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.util.Date;
import java.util.Objects;
import java.util.Set;

/**
 * @Class User
 * @Description 用户实体类 在数据中用户和角色是多对多关系通过中间表关联，因此用户内部有角色列表
 *   lombok注解@Data 包含了 @getter @setter @xxContructor  @ToString @HashAndEqual 等
 *   如果需要继承父类等着加上注解的属性 callSuper
 * @Author Administrator
 * @Date 2022-10-21  15:31
 * @version 1.0.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User extends BaseEntity {
    /**
     * 用户所拥有的多个角色，这里采用set不用list是避免role对象重复
     * 当然这个重复判定你hascode和equal的判断字段
     */
    private Set<Role> roles;
    /**
     * 编号
     */
    private String code;
    /**
     * 姓名
     */
    private String name;
    /**
     * 密码
     */
    private String password;
    /**
     * 头像
     */
    private String profilePicture;
    /**
     * 生日 注意采用 Util.date
     */
    private Date birthday;
    /**
     *  电话号码
     */
    private String tel;
    /**
     *  邮箱
     */
    private String email;
    /**
     *  其他
     */
    private String other;
    /**
     * 备注
     */
    private String remark;
    /**
     * 部门id 这里可以考虑组合Department对象
     */
    private Long departmentId;
    /**
     * 职位id 关联职位表 这里可以考虑定位为 Position
     */
    private Long positionId;


    public User(Long id,String code,String name){
        this.id=id;
        this.code=code;
        this.name=name;
    }

    public User(Long id, Long tenantId, Long orgId, Long companyId, Long createdBy, String creator, Date createdTime, Long updatedBy, Date updatedTime, String modifier, byte status, Long version, Set<Role> roles, String code, String name, String password, String profilePicture, Date birthday, String tel, String email, String other, String remark, Long departmentId, Long positionId) {
        super(id, tenantId, orgId, companyId, createdBy, creator, createdTime, updatedBy, updatedTime, modifier, status, version);
        this.roles = roles;
        this.code = code;
        this.name = name;
        this.password = password;
        this.profilePicture = profilePicture;
        this.birthday = birthday;
        this.tel = tel;
        this.email = email;
        this.other = other;
        this.remark = remark;
        this.departmentId = departmentId;
        this.positionId = positionId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        User user = (User) o;
        return Objects.equals(code, user.code) &&
                Objects.equals(name, user.name)&&Objects.equals(id,user.id);
    }

    /**
     *  依据 id code 和 name 来判别唯一
     * @return hashcode
     */
    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), code, name, id);
    }

    @Override
    public String toString() {
        return "User{" +
                "code='" + code + '\'' +
                ", name='" + name + '\'' +
                ", id=" + id +
                '}';
    }
}
